#ifndef __RAD_H__
#define __RAD_H__

#define DO_DIRECT_LIGHT
//#define DO_RADIOSITY

extern qboolean	noSurfaces;

#define	MAX_RADSAMPLES			65000
#define RADSAMPLES_BLOCKSIZE	1000
#define RAD_PATCH_REPORT_SCALE	64.0

// Structures shared in rad and vlight
typedef struct
{
	vec3_t		normal;
	float		dist;
} plane_t;

typedef struct lFacet_s
{
	int		num;
	plane_t	plane;
	vec3_t	points[4];				//
	int		numpoints;
	float	lightmapCoords[4][2];
	plane_t boundaries[4];			// negative is outside the bounds
	float	textureMatrix[2][4];	// texture coordinates for translucency
	float	lightmapMatrix[2][4];	// lightmap texture coordinates
	vec3_t	mins;
	int		x, y, width, height;
} lFacet_t;

void VL_RadSampleLightmaps( int num );


void CalcRadiosity(void);
void ApplyRadiosity(void);
void RadSamplePatchFacets(lFacet_t *facets, int numFacets);
void RadSampleTrisurfFacets(lFacet_t *facets, int numFacets, int planenum);
int RadNumSamples(void);
int RadPlaneCache(lFacet_t *facet);

void *RadTriangulateSequential(int firstSample, int numSamples, vec3_t normal);
void *RadTriangulatePlane(int firstSample, int numSamples, int planeindex);

void RadTriangulatePoint(void *surf, vec3_t point, vec3_t out);
void RadFreeTriangulation(void *ptr);

int VL_LightLeafnum(vec3_t point);

#endif
